package com.cn.wanxi.servlet;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.ImgModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.service.UploadService;
import com.cn.wanxi.service.impl.UploadServiceImpl;
import com.cn.wanxi.util.UpLoad;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Result;
import java.io.*;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@WebServlet("/upload")
public class FileUploadServlet extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        得到前端的值
        ImgModel imgModel = UpLoad.load(req);
        ResultModel resultModel = ResultModel.getResultModel(imgModel);
//        调用服务逻辑层
//        UploadService uploadService=new UploadServiceImpl();
//        得到结果
//        ResultModel resultModel=uploadService.upload();

//        返回前端
//        resp.getWriter().println(JSONObject.toJSONString(ResultModel.getResultModel(UpLoad.load(req))));
        resp.getWriter().println(JSONObject.toJSONString(resultModel));
    }

}
